package com.example.cloudcity.servlet;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/CartServlet")
public class CartServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String productName = request.getParameter("gameName"); // 获取商品名称
        String productPrice = request.getParameter("gameMoney"); // 获取商品价格
        String productImg = request.getParameter("gameImg"); // 获取商品图片URL
        String productTxt= request.getParameter("gameTxt");

        // 这里可以将商品信息存储到会话或数据库中
        // 示例：将商品信息存储到会话
        request.getSession().setAttribute("cartProduct", productName + " - ￥" + productPrice+"productImg"+productImg+"droducTTxt"+productTxt);

        response.setContentType("application/json");
        PrintWriter out = response.getWriter();
        out.print("{\"success\": true, \"message\": \"商品已添加到购物车\"}");
        out.flush();
    }
}